package com.atguigu.lease.common.globalException;

import com.atguigu.lease.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class Handler {

    @ExceptionHandler(value = Exception.class)
    public Result exceptionHandler(Exception e) {
        log.error("异常信息：{}", e.getMessage());
        e.printStackTrace();
        return Result.fail();
    }

    @ExceptionHandler(value = LeaseException.class)
    public Result leaseExceptionHandler(LeaseException e) {
        log.error("异常信息：{}", e.getMessage());
        return Result.fail(e.getCode(), e.getMessage());
    }
}
